<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="common/base.jsp"%>
<!DOCTYPE html>
<html>
<head lang="en">
    <%--head--%>
    <%@ include file="common/head.jsp"%>
    <title>登录</title>
</head>
<body class="login">
<div class="logo">
    <img src="<%=ctx%>/static/img/logo-text.png" alt="">
</div>
<div class="content">
    <h3>账号密码登录</h3>
    <div class="sp-cells">
        <div class="slin-row">
            <div class="slin-frame">
                <i class="icon-user"></i>
                <input type="text" class="sl-input allw" id="email" value="" placeholder="请输入账号">
            </div>
        </div>
        <div class="slin-row">
            <div class="slin-frame">
                <i class="icon-lock"></i>
                <input type="password" class="sl-input allw" id="password" value="" placeholder="请输入密码">
            </div>
        </div>
    </div>
    <div class="login-handle textcenter">
        <a class="slbtn btnblock login-btn" id="inSubmit">登 录</a>
    </div>
</div>
<%--foot--%>
<%@ include file="common/foot.jsp"%>
<script type="text/javascript" charset="UTF-8">
    var AjaxUrl = {
        "login": ajaxUrlBase + "userlogin"
    };
    //输入参数
    function getInData(){
        var $email = $("#email");
        var $password = $("#password");
        var inData = {};
        inData.username = $email.val();
        inData.password = $password.val();
        //删除前后的空白字符
        for(var para in inData){
            inData[para] = jQuery.trim(inData[para]);
        }
        return inData;
    }
    // 用户登录
    function userLogin(){
        var $email = $("#email");
        var $password = $("#password");
        var inData = new getInData();
        //输入校验
        do{
            if(!EmptyCheck($email, inData.username, "用户名不能为空")){
                break;
            }
            if(!PasswordCheck($password, inData.password)){
                break;
            }
            // 提交服务器
            layer.msg('加载中...', {icon: 16, shade: 0.1});
            //发送服务器
            $.ajax({
                type: "post",
                url: '/login',
                data: inData,
                dataType:"json",
                jsonp: "callback",
                success:function(data){
                    layer.closeAll();
                    var jsonData = eval(data);
                    var code = parseInt(jsonData['code']);
                    switch(code){
                        case CODEOK:
                            layer.msg('登录成功22！', {icon: 1, time: 1000});
                            // 跳转
                            setTimeout(function(){
                                window.location.replace("/home");
                            });
                            break;
                        case CODEERR:
                            layer.msg("登录失败22", {icon: 0, time: 1000});
                            break;
                        default:
                            var msg = jsonData["msg"];
                            layer.msg(msg, {icon: 0});
                    }
                },
                error:function(error){
                    console.log(error);
                    layer.closeAll();
                    layer.msg('登录失败33！', {icon: 2, time: 1000});
                }
            });
        }while(0);
    }
    $(document).ready(function(){
        // 登录
        $("#inSubmit").on("click", userLogin);
    });
</script>
</body>
</html>